package com.benmei.weike.dto.mcCourse;

import com.benmei.weike.common.Constants;
import com.benmei.weike.util.DateUtil;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * Created by Peter on 2018/10/8.
 */
public class McCourseDto {
    private Integer id;
    private String title;
    private String cover_small_url;// 封面图片，小图
    private String cover_large_url;// 封面图片，小图
    private Integer hot;// 是否热门：0否，1是
    private Date course_start_time;// 上课时间
    private Date course_end_time;
    private Integer cou_size;//课时数
    private Integer sale_state;//销售状态：0 未开始销售；1 预售；2 开始销售（限售）；3 售完
    private Integer buy_state = 0;//购买状态状态：0 未预定，未购买；1 已预订；2 已购
    private Integer max_buy_user_number;// 限购人数
    private Integer actual_buy_user_number;//实际购买人数
    private Date appointment_start_time;//预售时间
    private Date appointment_end_time;
    private Date sale_start_time;//开售时间
    private Date sale_end_time;
    private BigDecimal price;
    private List<McCourseTeacherDto> teacherList;

    public Integer getMax_buy_user_number() {
        return max_buy_user_number;
    }

    public void setMax_buy_user_number(Integer max_buy_user_number) {
        this.max_buy_user_number = max_buy_user_number;
    }

    public Integer getActual_buy_user_number() {
        return actual_buy_user_number;
    }

    public void setActual_buy_user_number(Integer actual_buy_user_number) {
        this.actual_buy_user_number = actual_buy_user_number;
    }

    public String getCover_large_url() {
        return cover_large_url;
    }

    public void setCover_large_url(String cover_large_url) {
        this.cover_large_url = cover_large_url;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getCover_small_url() {
        return cover_small_url;
    }

    public void setCover_small_url(String cover_small_url) {
        this.cover_small_url = cover_small_url;
    }

    public Integer getHot() {
        return hot;
    }

    public void setHot(Integer hot) {
        this.hot = hot;
    }

    public Date getCourse_start_time() {
        return course_start_time;
    }

    public void setCourse_start_time(Date course_start_time) {
        this.course_start_time = course_start_time;
    }

    public Date getCourse_end_time() {
        return course_end_time;
    }

    public void setCourse_end_time(Date course_end_time) {
        this.course_end_time = course_end_time;
    }

    public Integer getCou_size() {
        return cou_size;
    }

    public void setCou_size(Integer cou_size) {
        this.cou_size = cou_size;
    }

    public Integer getSale_state() {
        Long currentTime = System.currentTimeMillis();
        if (currentTime < this.appointment_start_time.getTime()) {
            sale_state = Constants.McCourse.SaleState.unStart;
        } else if (currentTime >= this.appointment_start_time.getTime() && currentTime <= this.appointment_end_time.getTime()) {
            sale_state = Constants.McCourse.SaleState.preSale;
        } else if (currentTime >= this.sale_start_time.getTime() && currentTime <= this.sale_end_time.getTime() && this.actual_buy_user_number >= this.max_buy_user_number) {
            sale_state = Constants.McCourse.SaleState.saleOver;
        } else if (currentTime > this.sale_end_time.getTime()) {
            sale_state = Constants.McCourse.SaleState.saleOver;
        } else {
            sale_state = Constants.McCourse.SaleState.sale;
        }
        return sale_state;
    }

    public void setSale_state(Integer sale_state) {
        this.sale_state = sale_state;
    }

    public Integer getBuy_state() {
        return buy_state;
    }

    public void setBuy_state(Integer buy_state) {
        this.buy_state = buy_state;
    }

    public String getStateText() {
        int s = this.getSale_state().intValue();

        if (s == 0 || s == 1) {
            return "限售" + this.max_buy_user_number + "人，将于" + DateUtil.format(this.sale_start_time, "yyyy.MM.dd HH:mm") + "开售";
        } else if (s == 2) {
            return "限售" + this.max_buy_user_number + "人，已有" + this.actual_buy_user_number + "人购买";
        } else {
            return "售完";
        }
    }

    public Date getAppointment_start_time() {
        return appointment_start_time;
    }

    public void setAppointment_start_time(Date appointment_start_time) {
        this.appointment_start_time = appointment_start_time;
    }

    public Date getAppointment_end_time() {
        return appointment_end_time;
    }

    public void setAppointment_end_time(Date appointment_end_time) {
        this.appointment_end_time = appointment_end_time;
    }

    public Date getSale_start_time() {
        return sale_start_time;
    }

    public void setSale_start_time(Date sale_start_time) {
        this.sale_start_time = sale_start_time;
    }

    public Date getSale_end_time() {
        return sale_end_time;
    }

    public void setSale_end_time(Date sale_end_time) {
        this.sale_end_time = sale_end_time;
    }

    public BigDecimal getPrice() {
        return price;
    }

    public void setPrice(BigDecimal price) {
        this.price = price;
    }

    public List<McCourseTeacherDto> getTeacherList() {
        return teacherList;
    }

    public void setTeacherList(List<McCourseTeacherDto> teacherList) {
        this.teacherList = teacherList;
    }
}
